package xyz.zhzby.cyzx.oj.controller;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.zhzby.cyzx.oj.dto.response.CategoryResponse;
import xyz.zhzby.cyzx.oj.service.ICategoryService;
import xyz.zhzby.cyzx.servicebase.domain.RestResponse;

import java.util.List;

/**
 * @author zby
 * @date 2021/12/26
 */
@RestController
@RequestMapping("/oj/category")
@ApiModel("试题分类相关API")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    @ApiOperation("创建试题分类")
    @PostMapping("")
    public RestResponse<String> createCategory(@RequestParam("categoryName") String categoryName) {
        return categoryService.createCategory(categoryName);
    }

    @ApiOperation("查看所有试题分类（不会很多，不用分页）")
    @GetMapping("/list")
    public RestResponse<List<CategoryResponse>> getAllCategorys() {
        return categoryService.getAllCategorys();
    }

    @ApiOperation("删除试题分类")
    @DeleteMapping("/{categoryId}")
    public RestResponse<String> deleteCategory(@PathVariable("categoryId") Long categoryId) {
        categoryService.removeById(categoryId);
        return RestResponse.success("删除成功");
    }

}
